1. Technical Field
The present invention relates in general to improved computer systems and in particular to an improved method and system for managing allocated memory heaps. Still more particularly, the present invention relates to an improved method and system for effective coalescing of memory blocks across memory heap boundaries in a computer system.
2. Description of the Related Art
Many computer systems support the dynamic allocation of memory. Memory is typically dynamically allocated among multiple tasks or multiple processors. For example, a multi-tasking operating system may have a memory manager, which allocates memory to each of the tasks. Additionally, certain programming languages support memory management. A program may request that the memory manager allocate a block of memory of a given size. The memory manager then determines which block of memory to allocate to the requesting program and passes to the requesting program a pointer to the allocated block of memory within the system memory. That portion of the program can thereafter utilize that memory. When the program no longer requires that memory the program informs the memory manager that the block has been “freed.” The memory manager typically de-allocates the block making it available to another processor or process. Memory designated for such use within a computer system is often referred to as “heap.”
As blocks of memory are allocated and de-allocated to processors or threads within a computer system such heaps of memory often become fragmented. That is, blocks of free space occur between blocks of allocated space. While there may be enough free space to satisfy an allocation request from a processor or process, it may not be contiguous. Additionally, the more fragmented a memory heap becomes the longer it may take to obtain sufficient free space for a block to satisfy a particular allocation request from a processor or process within the system. Many memory managers therefore attempt to defragment or “defrag” the memory by compacting or coalescing the memory heaps. The goal of memory coalescing is therefore to move allocated blocks of memory together so as to merge the free space available into large blocks of memory rather than many small blocks of memory.
Prior art techniques for coalescing blocks of memory within multiple memory heaps typically do so within the boundaries of an individual memory heap. Attempts at coalescing memory across memory heap boundaries have typically required that access to all memory heaps be limited or locked so that memory may be freely allocated and de-allocated, copying existing data into newly freed memory blocks so that the memory may be utilized more efficiently. It should therefore be apparent that it would be desirable to provide a method and system whereby memory could be coalesced across memory heap boundaries without requiring that access to all memory heaps be temporarily suspended.